package cn.blackbirds.blocks;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import cn.blackbirds.blocks.layer.GameLayer;
import cn.blackbirds.blocks.layer.MenuScene;

import com.wiyun.engine.nodes.Director;
import com.wiyun.engine.sound.AudioManager;
import com.wiyun.engine.transitions.ColorFadeTransition;
import com.wiyun.engine.transitions.TransitionScene;
import com.wiyun.engine.types.WYColor3B;


/**
 * 游戏主类，负责所有场景的切换
 * 
 * @author jang created at 20111001
 * 
 */
public class MainActivity extends ActivityTemplate {
	static {
		System.loadLibrary("wiskia");
		System.loadLibrary("xml2");
		System.loadLibrary("wiengine");
		System.loadLibrary("wisound");
	}
	public static float WIN_WIDTH;
	public static float WIN_HEIGHT;
	public static float SCALE_X;
	public static float SCALE_Y;
	
	@Override
	protected void createScene() {
		WIN_WIDTH = Director.getInstance().getWindowSize().width;
		WIN_HEIGHT = Director.getInstance().getWindowSize().height;
		SCALE_X = 1;
		SCALE_Y = 1;
		
		mScene = new MenuScene(this);
		mScene.autoRelease(true);

	}
	
	public void showExitConfirm() {
		runOnUiThread(new Runnable() {
			public void run() {
				AlertDialog.Builder builder = new Builder(MainActivity.this);
				builder.setMessage(R.string.exit_confirm)
				.setNegativeButton(R.string.no, null)
				.setPositiveButton(R.string.yes, new OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {						
						finish();
					}
				}).show();
			}
		});
	}
	
	public void showExitRemoveBallConfirm() {
		runOnUiThread(new Runnable() {
			public void run() {
				AlertDialog.Builder builder = new Builder(MainActivity.this);
				builder.setMessage(R.string.game_exit_confirm)
				.setNegativeButton(R.string.no, null)
				.setPositiveButton(R.string.yes, new OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						OpenFeintLeaderboard openFeintLeaderboard = new OpenFeintLeaderboard();
						openFeintLeaderboard.sendScore(GameLayer.score);		
						GameLayer.score = 0;
						Globals.onPlayBg();
						Director.getInstance().popSceneWithTransition((TransitionScene)ColorFadeTransition.make(2, null, new WYColor3B(0, 0, 0)).autoRelease());
					}
				}).show();
			}
		});
	}
	
	

	
}
